package com.ps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ps.pojo.Systemconfig;
import com.ps.mapper.SystemconfigMapper;
import com.ps.service.SystemconfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 系统配置表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-12-18
 */
@Service("systemconfigService")
public class SystemconfigServiceImpl extends ServiceImpl<SystemconfigMapper, Systemconfig> implements SystemconfigService {
    @Resource
    private SystemconfigMapper systemconfigMapper;
    @Override
    public Page<Systemconfig> getAll(Integer page, Integer limit, Systemconfig systemconfig) {
        Page<Systemconfig> systemconfigPage =new Page<>(page,limit);
        QueryWrapper<Systemconfig> wrapper=new QueryWrapper<>();
        wrapper.eq("configCode","BUG_TYPE");
        systemconfigPage=systemconfigMapper.selectPage(systemconfigPage,wrapper);
        return systemconfigPage;
    }

    @Override
    public Boolean add(Systemconfig systemconfig) {
        boolean flag=false;
        QueryWrapper<Systemconfig>wrapper=new QueryWrapper<>();
        wrapper.eq("configcode","BUG_TYPE");
        wrapper.orderByDesc("configValueId");
        wrapper.last("limit 1");
        Systemconfig one = getOne(wrapper);
        systemconfig.setConfigcode(one.getConfigcode());
        systemconfig.setConfigname(one.getConfigname());
        systemconfig.setConfigvalueid(one.getConfigvalueid()+1);
        if (systemconfigMapper.insert(systemconfig)!=0){
            flag=true;
        }
        return flag;
    }
}
